# Makefile for X11 interface to Xconq.
# Copyright (C) 1991, 1992, 1993, 1994, 1995 Stanley T. Shebs.

# Xconq is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# Where xconq itself lives.

prefix = .

exec_prefix = $(prefix)
bindir = $(exec_prefix)
# this should be tweaked
libdir = $(srcdir)/../lib
datadir = $(prefix)/lib
mandir = $(prefix)/man
man6dir = $(mandir)/man6
infodir = $(prefix)/info
docdir = $(datadir)/doc

srcdir = .

krnsrcdir = $(srcdir)/../kernel

# Set this for wherever the library directory should be.

LIBDIR = $(srcdir)/../lib

IMFLIBDIR = $(srcdir)/../lib-x11

SHELL = /bin/sh

INSTALL = `cd $(srcdir)/..;pwd`/install.sh -c
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL)

CC = cc

CFLAGS = -g

# Ditto for X font libraries.
#XFONTPATH = /usr/local/X11/lib/fonts/misc

X11_LIB = -lXmu -lX11

XAW_LIB = -L../SelFile -lXgnu -lXaw -lXt $(X11_LIB) -lXext -lm

# Override this in order to point at the Xpm include files.

XPM_INCLUDE_FLAGS =

# Override this in order to point at the Xpm library.

XPM_LIB = -lXpm

WITH_LIBS = 

# Host and target-dependent makefile fragments come in here.
####
# End of host and target-dependent makefile fragments.

GAME_H = $(krnsrcdir)/game.h \
	 $(krnsrcdir)/gvar.def \
	 $(krnsrcdir)/utype.def \
	 $(krnsrcdir)/mtype.def \
	 $(krnsrcdir)/ttype.def \
	 $(krnsrcdir)/table.def

UNIT_H = $(krnsrcdir)/unit.h \
	 $(krnsrcdir)/action.def \
	 $(krnsrcdir)/plan.def \
	 $(krnsrcdir)/task.def

ALL_H = $(krnsrcdir)/conq.h \
	$(krnsrcdir)/config.h \
	$(krnsrcdir)/misc.h \
	$(krnsrcdir)/dir.h \
	$(krnsrcdir)/lisp.h \
	$(krnsrcdir)/module.h \
	$(GAME_H) \
	$(krnsrcdir)/player.h \
	$(krnsrcdir)/side.h \
	$(UNIT_H) \
	$(krnsrcdir)/goal.def \
	$(krnsrcdir)/world.h \
	$(krnsrcdir)/score.h \
	$(krnsrcdir)/history.h \
	$(krnsrcdir)/ai.h

X_H = $(srcdir)/xconq.h $(srcdir)/xcmd.def

# Interface-specific object files.

XOBJS =	xconq.o \
	xinit.o \
	xmap.o \
	xdraw.o \
	xcmd.o \
	xprint.o \
	xdesign.o \
	xhelp.o \
	ximf.o

XUTOBJS = ximf.o \
	 xutil.o

UNIX_CFLAGS = -DUNIX -DUSE_CONSOLE -DXCONQLIB=\"$(libdir)\" -DIMFLIB=\"$(IMFLIBDIR)\"

ALL_CFLAGS = $(CFLAGS) $(XPM_CFLAGS) $(REQD_CFLAGS) $(UNIX_CFLAGS) -I$(srcdir) -I$(krnsrcdir) $(X11_INCLUDE_FLAGS)

.c.o:
	$(CC) -c $(ALL_CFLAGS) $<

# Do it all.

all:	xconq Xconq Xconq-co x2imf imf2x xshowimf XShowimf XShowimf-co

# The game itself.

xconq: $(XOBJS) ../kernel/libconq.a ../kernel/libconqlow.a
	rm -f xconq
	$(CC) -o xconq $(ALL_CFLAGS) $(XOBJS) ../kernel/libconq.a ../kernel/libconqlow.a $(X11_LIB_FLAGS) $(WITH_LIBS) $(XAW_LIB)

../kernel/libconq.a:
	(cd ../kernel; make libconq.a; cd ../x11)

../kernel/libconqlow.a:
	(cd ../kernel; make libconqlow.a; cd ../x11)

# X-related utilities.

x2imf:	x2imf.o $(XUTOBJS) ../kernel/libconqlow.a
	$(CC) -o x2imf x2imf.o $(XUTOBJS) ../kernel/libconqlow.a $(ALL_CFLAGS) $(X11_LIB_FLAGS) $(WITH_LIBS) $(XAW_LIB)

imf2x:	imf2x.o $(XUTOBJS) ../kernel/libconqlow.a
	$(CC) -o imf2x imf2x.o $(XUTOBJS) ../kernel/libconqlow.a $(ALL_CFLAGS) $(X11_LIB_FLAGS) $(WITH_LIBS) $(XAW_LIB)

xshowimf:	xshowimf.o $(XUTOBJS) ../kernel/libconqlow.a
	$(CC) -o xshowimf xshowimf.o $(XUTOBJS) ../kernel/libconqlow.a $(ALL_CFLAGS) $(X11_LIB_FLAGS) $(WITH_LIBS) $(XAW_LIB)

# Resources.

Xconq:	Xconq.ad
	cp $(srcdir)/Xconq.ad Xconq

Xconq-co:	Xconq-co.ad
	cp $(srcdir)/Xconq-co.ad Xconq-co

XShowimf:	XShowimf.ad
	cp $(srcdir)/XShowimf.ad XShowimf

XShowimf-co:	XShowimf-co.ad
	cp $(srcdir)/XShowimf-co.ad XShowimf-co

# Installation requires programs in $(DESTDIR) and a library directory.
# Also, fonts might have to go in system's font directory.
# No standard place for formatted docs, you're on your own...


install: all install-only

install-only:
	$(INSTALL_PROGRAM) xconq $(bindir)
	$(INSTALL_PROGRAM) imf2x $(bindir)
	$(INSTALL_PROGRAM) x2imf $(bindir)
	$(INSTALL_PROGRAM) xshowimf $(bindir)
	$(INSTALL_DATA) $(srcdir)/xconq.6 $(man6dir)

# Font installation.

install-fonts:
	echo will borrow from 5.5 when fonts are supported

# Cleanliness support.

clean:
	rm -f *.o lint.out core
	rm -f xconq *.conq *.xconq Xconq Xconq-co
	rm -f imf2x x2imf xshowimf XShowimf XShowimf-co

distclean: clean
	rm -f Makefile config.status

extraclean: distclean
	rm -f *~* .*~*

realclean: distclean

Makefile: Makefile.in $(host_makefile_frag) $(target_makefile_frag)
	$(SHELL) config.status

# Dependencies.

xconq.o:	$(ALL_H) $(X_H)
xinit.o:	$(ALL_H) $(X_H)
xmap.o:		$(ALL_H) $(X_H)
xcmd.o:		$(ALL_H) $(X_H)
xdraw.o:	$(ALL_H) $(X_H)
xprint.o:	$(ALL_H) $(X_H)
xdesign.o:	$(ALL_H) $(X_H)
xhelp.o:	$(ALL_H) $(X_H)
ximf.o:		$(ALL_H) $(X_H)
